using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Text = TMPro.TMP_Text;

public class PlayerProp : MonoSingleton<PlayerProp> {
	public int hp;
	public int maxHp;
	public int food;
	public int maxFood;
	public int endurance;
	public int maxEndurance;
	public Text mrCounterText;

	public int mushroomCnt {
		get {
			return m_mushRoomCnt;
		}
		set {
			m_mushRoomCnt = value;
			RefreshMRUI();
		}
	}
	[SerializeField]
	private int m_mushRoomCnt = 1;

	public Dictionary<ItemId, int> inventory = new Dictionary<ItemId, int>();
	public float enduranceFill => Mathf.Clamp01((float)endurance / Mathf.Max(1, maxEndurance));

	public void RefillEndurance() {
		endurance = maxEndurance;
	}

	public void OnReloadGame() {
		hp = maxHp;
		endurance = maxEndurance;
		mushroomCnt = 2;
	}

	public void RefreshMRUI() {
		mrCounterText.text = $"x{m_mushRoomCnt}";
	}

	public void AddItem(ItemId itemId, int cnt) {
		var before = inventory.GetValueOrDefault(itemId);
		inventory[itemId] = before + cnt;
		PopupTipManager.Instance.ShowGainItem(itemId, cnt);

		if (itemId == ItemId.HeartCrystal) {
			hp = hp + 1 > maxHp ? maxHp : hp + 1;
		}
		if (itemId == ItemId.Mushroom) {
			mushroomCnt += cnt;
		}
	}
}
